package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter@ToString
public class Travel extends BaseDomain{
    public static final Integer STATE_COMMON =0;//草稿
    public static final Integer STATE_AUDIT =1;//审核中
    public static final Integer STATE_RELEASE=2;//发布成功
    public static final Integer STATE_REJECT=-1;//拒绝发布

    public static final Integer PERSON_ALONE=1;//一个人的旅行
    public static final Integer PERSON_PARENT=2;//和父母
    public static final Integer PERSON_FRIEND=3;//和朋友
    public static final Integer PERSON_WORK =4;//和同事
    public static final Integer PERSON_GIRLFRIEND=5;//和爱人
    public static final Integer PERSON_OTHER=6;//和其他



    //标题
    private String title;
    //旅游时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    //花费
    private String perExpends;
    //旅游天数
    private Integer days;
    //和谁去旅行
    private Integer person=PERSON_ALONE;
    //发布者
    private User author;
    //创建游记时间
    private Date createTime;
    //发布游记时间
    private Date releaseTime;
    //是否公开
    private Boolean isPublic=false;
    //旅行地址
    private Region place;
    //背景图片
    private String coverUrl;
    //最后修改时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;
    //状态
    private Integer state=STATE_COMMON;

    private TravelContent travelContent;

     /*<option value="1" selected>一个人的旅行</option>
                <option value="2">和父母</option>
                <option value="3">和朋友</option>
                <option value="4">和同事</option>
                <option value="5">和爱人</option>
                <option value="6">和其他</option>*/
    public String getPersonName (){
        String personName = "和其他";
        if ( PERSON_PARENT.equals(person)  ) {
            personName="和父母";
        }else if (PERSON_FRIEND.equals(person) ){
            personName="和朋友";
        }else if (PERSON_WORK.equals(person) ){
            personName="和同事";
        }else if (PERSON_GIRLFRIEND.equals(person) ){
            personName="和爱人";
        }else if (PERSON_ALONE.equals(person) ){
            personName="一个人的旅行";
        }

        return personName;
    }

    public String getStateName (){
        String stateName = "草稿";
        if (STATE_AUDIT == state) {
            stateName="审核中";
        }else if (STATE_RELEASE==state){
            stateName="发布成功";
        }else if (STATE_REJECT==state){
            stateName="拒绝发布";
        }

        return stateName;
    }

    public Object getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("travelTime",travelTime);
        map.put("days",days);
        map.put("person",person);
        map.put("author",author);
        map.put("createTime",createTime);
        map.put("releaseTime",releaseTime);
        map.put("isPublic",isPublic);
        map.put("place",place);
        map.put("coverUrl",coverUrl);
        map.put("lastUpdateTime",lastUpdateTime);
        map.put("state",state);
        map.put("travelContent",travelContent);
        return JSONUtil.toJSONString(map);
    }
}